<template>
  <div class="lab box">
    <!-- <img
      src="@/assets/img/goback.png"
      class="goback"
      v-show="$store.state.cn_scence_ctrl_show"
      @click.capture="goBack"
    /> -->
    <!-- 中英文切换 -->
    <div class="changelangbox">
      <div
        v-for="item in langlist"
        :key="item.id"
        :class="[
          item.id,
          item.id == 'en' ? 'clmcenter' : '',
          item.active ? 'active' : '',
        ]"
        @click="$router.replace('/en/map')"
      >
        <span>{{ item.name }}</span>
      </div>
    </div>
    <router-view ref="sonele" />
    <!-- 底部控制区 -->
    <div class="ctrlbox" v-show="$store.state.cn_scence_ctrl_show">
      <!-- 场景 -->
      <div class="sencebox" ref="scrollbox" v-show="scenseshow">
        <div class="scrollbox">
          <div
            :class="['scrollitem', item.active ? 'active' : '']"
            v-for="item in scenceList"
            :key="item.id"
            @click="changeSence(item)"
          >
            <img :src="item.img" />
            <p class="stitle">{{ item.title }}</p>
          </div>
        </div>
      </div>
      <!-- 按钮区 -->
      <div class="btnbox">
        <div class="bitem" @click="goBack">
          <img src="@/assets/img/icon_map.png" class="b_icon icon_map" />
          <p>地图</p>
        </div>
        <div class="bitem" @click="scenseshow = !scenseshow">
          <img src="@/assets/img/icon_menu.png" class="b_icon icon_menu" />
          <p>场景选择</p>
        </div>
        <div class="bitem" @click="showLabDesc">
          <img src="@/assets/img/btn_1.png" class="b_btn btn_desc" />
          <p>实验室介绍</p>
        </div>
        <div
          class="bitem"
          @click="$router.replace({ path: '/cn/contact', query: { id } })"
        >
          <img src="@/assets/img/btn_2.png" class="b_btn btn_contact" />
          <p>联系我们</p>
        </div>
        <div class="bitem">
          <img
            src="@/assets/img/btn_3.png"
            class="b_btn btn_download"
            @click="$router.replace({ path: '/cn/download', query: { id } })"
          />
          <p>了解更多</p>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      // 场景
      scenceList: [
        {
          id: "itemA",
          img: require("@/assets/img/CN/itemA/poster.jpg"),
          title: "表面处理实验室",
          active: false,
        },
        {
          id: "itemC",
          img: require("@/assets/img/CN/itemC/poster.jpg"),
          title: "浸涂电泳模拟线",
          active: false,
        },
        {
          id: "itemB",
          img: require("@/assets/img/CN/itemB/poster.jpg"),
          title: "粉末喷房",
          active: false,
        },
        {
          id: "itemD",
          img: require("@/assets/img/CN/itemD/poster.jpg"),
          title: "盐雾测试实验室",
          active: false,
        },
        {
          id: "itemE",
          img: require("@/assets/img/CN/itemE/poster.jpg"),
          title: "环境测试实验室",
          active: false,
        },
        {
          id: "itemF",
          img: require("@/assets/img/CN/itemF/poster.jpg"),
          title: "综合仪器分析室",
          active: false,
        },
        {
          id: "itemG",
          img: require("@/assets/img/CN/itemG/poster.jpg"),
          title: "荧光光谱实验室",
          active: false,
        },
        {
          id: "itemH",
          img: require("@/assets/img/CN/itemH/poster.jpg"),
          title: "扫描电镜实验室",
          active: false,
        },
      ],
      scenseshow: false, //场景
      id: "",
      langlist: [
        { id: "cn", name: "中文", active: true },
        { id: "en", name: "EN", active: false },
      ],
    };
  },
  created() {
    this.id = this.$route.path.substring(
      this.$route.path.length - 5,
      this.$route.path.length
    );
    // console.log(this.id);
    this.scenceList.forEach((item, index) => {
      if (item.id == this.id) {
        item.active = true;
        if (index >= 5) {
          // console.log(index);
          this.$nextTick(() => {
            this.$refs.scrollbox.scrollLeft = 500;
          });
        }
        this.$router.replace(`/cn/lab/${item.id}`);
      } else {
        item.active = false;
      }
    });
  },
  methods: {
    // 切换场景
    changeSence(el) {
      this.scenceList.forEach((item) => {
        if (item.id == el.id) {
          if (!item.active) {
            this.$store.commit("updateCnScenceCtrlShow", false);
          }
          item.active = true;
          this.$router.replace(`/cn/lab/${item.id}`);
        } else {
          item.active = false;
        }
      });
    },
    // 显示 子级的 自动弹窗
    showLabDesc() {
      if (!this.$refs.sonele.entershow) {
        this.$store.commit("updateCnScenceCtrlShow", false);
        this.$refs.sonele.entershow = true;
      }
    },
    // 返回
    goBack() {
      this.$router.replace("/cn/map");
    },
  },
};
</script>
<style lang="less" scoped>
.lab {
  background: #000000;
  color: #ffffff;
  .goback {
    position: absolute;
    z-index: 9;
    margin: 2rem;
    width: 61px;
  }
  .ctrlbox {
    position: absolute;
    bottom: 0;
    width: 100%;
    .sencebox {
      width: 100%;
      margin-bottom: 2rem;
      overflow-x: scroll;
      white-space: nowrap;
      .scrollbox {
        width: max-content;
        height: 100%;
        display: flex;
        justify-content: flex-start;
        align-items: center;
        .scrollitem {
          display: inline-block;
          position: relative;
          width: 120px;
          height: 120px;
          border: 4px solid #ffffff;
          margin: 0 0.7rem;
          img {
            width: 100%;
            height: 100%;
            object-fit: cover;
          }
          .stitle {
            position: absolute;
            bottom: 0;
            width: 100%;
            height: 30px;
            line-height: 30px;
            background: rgba(0, 0, 0, 0.6);
            font-size: 1.2rem;
            text-align: center;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
          }
        }
        .active {
          border: 4px solid #e4ac4a;
        }
      }
    }
    .btnbox {
      display: flex;
      justify-content: space-evenly;
      margin-bottom: 1.5rem;
      .bitem {
        text-align: center;
        .b_icon {
          width: 47px;
        }
        .b_btn {
          width: 164px;
        }
        p {
          font-size: 1.2rem;
          padding-top: 0.5rem;
          text-align: center;
        }
      }
    }
  }
}
@media only screen and (min-height: 1400px) {
  .lab {
    .ctrlbox {
      .btnbox {
        margin-bottom: 3rem;
      }
    }
  }
}
</style>
